#!/bin/bash

DBUSR='xxx'
DBPWD='xxx'
MYSQL_PWD='xxx'
SLOW_LOG_FILE='xxx.slow.log'
SLOW_TIME=5

mysql -uroot -p${MYSQL_PWD} <<EOF
set global slow_query_log=on;
set global long_query_time=5;
EOF

pt-query-digest --user=${DBUSR} --password=${DBPWD} --review h=10.10.10.11,D=slow_query_log,t=global_query_review \
--history h=10.10.10.11,D=slow_query_log,t=global_query_review_history \
--no-report --limit=0% --filter "\$event->{Bytes} = length(\$event->{arg}) and \$event->{hostname}=\"$HOSTNAME\" and (\$event->{fingerprint} =~ m/^select/i or \$event->{fingerprint} =~ m/^update/i or \$event->{fingerprint} =~ m/^delete/i or \$event->{fingerprint} =~ m/^insert/i or \$event->{fingerprint} =~ m/^replace/i) " \
${SLOW_LOG_FILE}